# -*- coding: utf-8 -*-
import hashlib
from log import logger
import pickle

logger = logger()


class MD5(object):
    """
    A class is used for encrypt character
    """
    md5 = hashlib.md5()

    @classmethod
    def encryption(cls, arg=None):
        """
        Return a encryption character if parameter arg is None
        else return a null character
        :param arg:
        :return:
        """
        if arg and isinstance(arg, str):
            arg = arg.encode("utf-8")
            cls.md5.update(arg)
            return cls.md5.hexdigest()
        else:
            logger.debug("arg is not a character or length is shorter than 1")
            return ""


class GenerateRegisterFile(object) :
    """
    A class generate register file
    """

    @staticmethod
    def generate(filename, instance):
        try:
            file = open(filename, "wb")
            pickle.dump(obj=instance, file=file)
        except FileNotFoundError as e:
            logger.error(e)
        else:
            file.close()


if __name__ == "__main__":
    # MD5.encryption()
    GenerateRegisterFile.generate("registry.conf", )
    logger.info("ddddddddddddd")
